package com.promise.jokerdream.ui.settings

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.clickable
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.promise.jokerdream.ui.components.SettingCard
import com.promise.jokerdream.ui.components.RoundCheckbox
import com.promise.jokerdream.ui.theme.AppSpacing
import com.promise.jokerdream.ui.theme.AppFontSizes
import com.promise.jokerdream.database.entity.WlmzGameConfigEntity
import com.promise.jokerdream.config.game.WlmzGroundType

/**
 * 武林盟主设置卡片
 */
@Composable
fun WlmzSettingCard(
    config: WlmzGameConfigEntity,
    onWlmzChange: (Boolean) -> Unit,
    onGroundTypeChange: (WlmzGroundType) -> Unit,
    modifier: Modifier = Modifier,
    onExecuteClick: (() -> Unit)? = null
) {
    SettingCard(
        title = "武林盟主",
        description = "",
        checked = config.enabledSetting,
        onCheckedChange = onWlmzChange,
        modifier = modifier,
        onExecuteClick = onExecuteClick,
        content = {
            if (config.enabledSetting) {
                // 赛场选择 - 一行三个RoundCheckbox
                Row(
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(vertical = AppSpacing.componentSmall),
                    horizontalArrangement = Arrangement.spacedBy(AppSpacing.componentMedium)
                ) {
                    WlmzGroundType.values().forEach { groundType ->
                        Row(
                            modifier = Modifier
                                .weight(1f)
                                .clickable { onGroundTypeChange(groundType) },
                            verticalAlignment = Alignment.CenterVertically
                        ) {
                            RoundCheckbox(
                                checked = config.groundType == groundType.name,
                                onCheckedChange = { 
                                    if (it) onGroundTypeChange(groundType)
                                }
                            )
                            Spacer(modifier = Modifier.width(AppSpacing.componentMedium))
                            Text(
                                text = getGroundTypeDisplayName(groundType),
                                fontSize = AppFontSizes.mediumBody,
                                color = MaterialTheme.colorScheme.onSurface
                            )
                        }
                    }
                }
            }
        }
    )
}

/**
 * 获取赛场类型显示名称
 * @param groundType 赛场类型
 * @return 显示名称
 */
private fun getGroundTypeDisplayName(groundType: WlmzGroundType): String {
    return when (groundType) {
        WlmzGroundType.GOLD -> "黄金赛场"
        WlmzGroundType.SILVER -> "白银赛场"
        WlmzGroundType.BRONZE -> "青铜赛场"
    }
}
